﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using YFurion.Entities;
using YFurion.Utils;

namespace UpperComputer.Core.Entities
{
    public class BaseMenuButton : FullEntity, IEntityTypeBuilder<BaseMenuButton>, IEntitySeedData<BaseMenuButton>
    {
        public string Code { get; set; }

        public string DisplayName { get; set; }

        public string MenuCode { get; set; }

        public int Sort { get; set; }

        public string Icon { get; set; }

        public bool IsSplit { get; set; }

        public bool IsActive { get; set; }

        public string Description { get; set; }

        public virtual BaseMenu MenuCodeNavigation { get; set; }

        public void Configure(EntityTypeBuilder<BaseMenuButton> entity, DbContext dbContext, Type dbContextLocator)
        {
            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("编号");

            entity.Property(e => e.Code)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("编码");

            entity.Property(e => e.CreationTime).HasComment("创建时间");

            entity.Property(e => e.CreatorUserId)
                .HasComment("创建者编号");

            entity.Property(e => e.DeleterUserId)
                .HasComment("删除者编号");

            entity.Property(e => e.DeletionTime).HasComment("删除时间");

            entity.Property(e => e.Description)
                .HasMaxLength(255)
                .HasComment("描述");

            entity.Property(e => e.DisplayName)
                .IsRequired()
                .HasMaxLength(50)
                .HasComment("显示名称");

            entity.Property(e => e.Icon)
                .HasMaxLength(100)
                .HasComment("图标");

            entity.Property(e => e.IsActive).HasComment("是否激活");

            entity.Property(e => e.IsDeleted).HasComment("是否删除");

            entity.Property(e => e.IsSplit).HasComment("是否有分割线");

            entity.Property(e => e.LastModificationTime).HasComment("最后一次修改时间");

            entity.Property(e => e.LastModifierUserId)
                .HasComment("最后一次修改者编号");

            entity.Property(e => e.MenuCode)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("菜单编码");

            entity.Property(e => e.Sort).HasComment("排序");

            entity.HasOne(d => d.MenuCodeNavigation)
                   .WithMany(p => p.BaseMenuButton)
                   .HasPrincipalKey(p => p.Code)
                   .HasForeignKey(d => d.MenuCode)
                   .OnDelete(DeleteBehavior.ClientSetNull)
                   .HasConstraintName("FK_BaseMenuButton_BaseMenu");
        }

        public IEnumerable<BaseMenuButton> HasData(DbContext dbContext, Type dbContextLocator)
        {
            return new List<BaseMenuButton>()
            {
                #region 菜单的功能
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Post",
                    MenuCode = "Menu",
                    DisplayName = "添加",
                    Icon = "FileAddOutlined",
                    IsActive = true,
                    Sort = 1,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单的添加"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Put",
                    MenuCode = "Menu",
                    DisplayName = "编辑",
                    Icon = "EditOutlined",
                    IsActive = true,
                    Sort = 2,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单的编辑"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Delete",
                    MenuCode = "Menu",
                    DisplayName = "删除",
                    Icon = "DeleteOutlined",
                    IsActive = true,
                    Sort = 3,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单的删除"
                },
                #endregion

                #region 菜单按钮的功能
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Post",
                    MenuCode = "MenuButton",
                    DisplayName = "添加",
                    Icon = "FileAddOutlined",
                    IsActive = true,
                    Sort = 1,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单按钮的添加"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Put",
                    MenuCode = "MenuButton",
                    DisplayName = "编辑",
                    Icon = "EditOutlined",
                    IsActive = true,
                    Sort = 2,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单按钮的编辑"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Delete",
                    MenuCode = "MenuButton",
                    DisplayName = "删除",
                    Icon = "DeleteOutlined",
                    IsActive = true,
                    Sort = 3,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单按钮的删除"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "CopyButton",
                    MenuCode = "MenuButton",
                    DisplayName = "复制按钮",
                    Icon = "SyncOutlined",
                    IsActive = true,
                    Sort = 4,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "菜单按钮的复制按钮"
                },
                #endregion

                #region 角色的功能
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Post",
                    MenuCode = "Role",
                    DisplayName = "添加",
                    Icon = "FileAddOutlined",
                    IsActive = true,
                    Sort = 1,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "角色的添加"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Put",
                    MenuCode = "Role",
                    DisplayName = "编辑",
                    Icon = "EditOutlined",
                    IsActive = true,
                    Sort = 2,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "角色的编辑"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Delete",
                    MenuCode = "Role",
                    DisplayName = "删除",
                    Icon = "DeleteOutlined",
                    IsActive = true,
                    Sort = 3,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "角色的删除"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "GivePermissions",
                    MenuCode = "Role",
                    DisplayName = "分配权限",
                    Icon = "SettingOutlined",
                    IsActive = true,
                    Sort = 4,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "角色的分配权限"
                },
                #endregion

                #region 用户的功能
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Post",
                    MenuCode = "User",
                    DisplayName = "添加",
                    Icon = "FileAddOutlined",
                    IsActive = true,
                    Sort = 1,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的添加"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Put",
                    MenuCode = "User",
                    DisplayName = "编辑",
                    Icon = "EditOutlined",
                    IsActive = true,
                    Sort = 2,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的编辑"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Recover",
                    MenuCode = "User",
                    DisplayName = "重置密码",
                    Icon = "CompassOutlined",
                    IsActive = true,
                    Sort = 3,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的重置密码"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Enable",
                    MenuCode = "User",
                    DisplayName = "启用",
                    Icon = "CheckCircleOutlined",
                    IsActive = true,
                    Sort = 4,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的启用"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Disable",
                    MenuCode = "User",
                    DisplayName = "禁用",
                    Icon = "PropertySafetyOutlined",
                    IsActive = true,
                    Sort = 5,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的禁用"
                },
                new BaseMenuButton
                {
                    Id =  YIDGenerator.NextId(),
                    Code = "Delete",
                    MenuCode = "User",
                    DisplayName = "删除",
                    Icon = "DeleteOutlined",
                    IsActive = true,
                    Sort = 6,
                    CreationTime = DateTime.Now,
                    //CreatorUserId = 0,
                    Description = "用户的删除"
                }
                #endregion
            };
        }
    }
}